package cn.zust.ly.play.Exa;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by liy on 2016/12/1.
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int price[] = new int[m];
        int resCount = 0;
        int result[] = new int[m];
        List<int[]> res = new ArrayList<>();
        List<int[]> ress = new ArrayList<>();
       // int resMax[] = new int[m];

        for (int i = 0; i < m; i++) {
            price[i] = sc.nextInt();
            //resMax[i] = 1000/price[i]+1;
        }
        getSP(1000, result, price,res);

        System.out.println(res.size());
        for (int i = 0; i < res.size(); i++) {
            for (int j = 0; j < res.get(i).length; j++) {
                System.out.print(res.get(i)[j]+" ");
            }
           // System.out.println(res.toString());
        }

    }

    static List<int[]> res = new ArrayList<>();

    static List<int[]> getSP (int shePrice,  int[] a, int price[],List<int[]> res){

        for (int i = 0; i < price.length; i++) {

            if (shePrice >= price[i]) {
                int sp = shePrice - price[i];
                a[i]++;
                if (sp == 0){
                    res.add(a);
                   // System.out.println(a[0]+"--"+a[1]);
                }
                else
                    res = getSP(sp, a, price,res);
            }

        }

    return res;
    }

}
